package main

import (
	"fmt"
	"log"
	"os"
	"sort"

	"github.com/urfave/cli"

	"./commands"
	"./etc"
	"./utils"
)

var config utils.Config

func init() {
	config = config.News()
}

func main() {
	app := cli.NewApp()
	app.Name = "Sakura Git Branch Manager (SGBM)"
	app.Version = etc.Ver
	app.Usage = "A simple tool for git!"
	app.Authors = []cli.Author{
		{
			Name:  "Sakura Mo",
			Email: "moyinzi@outlook.com",
		},
	}

	// Commands
	app.Commands = []cli.Command{
		commands.Init(config),
		commands.Master(config),
		commands.Dev(config),
		commands.Fresh(config),
		commands.Beta(config),
		commands.Add(config),
		commands.Remove(config),
		commands.Login(config),

		commands.Task(config),
		commands.TaskList(config),
		commands.Workplace(config),
		commands.Publish(config),
		commands.Apply(config),
	}

	// [default]
	// example for use as:
	// $ ./sgbm
	app.Action = func(c *cli.Context) error {
		fmt.Println("Hello, SGBM!")
		return nil
	}

	// sort output
	sort.Sort(cli.FlagsByName(app.Flags))
	sort.Sort(cli.CommandsByName(app.Commands))

	// run cli
	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}
}
